﻿using System;
using System.Collections.Generic;
using System.Text;
using KPIS.DBM;
using System.Configuration;
using KPIS.GERP.GIMS.MODEL;
using System.Data;

namespace KPIS.GERP.GIMS.DAL
{
    public class D_Requisition
    {
        DBManager dbManager = new DBManager(DataProvider.MySQL, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        ConvertNullable cn = new ConvertNullable();

        public IList<M_Requisition> GetListForUserFillByEmpSeq(string status_request)
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_Requisition> infoList = new List<M_Requisition>();
            try
            {
                dbManager.Open();
                string strAfterwhere = "";

                switch (status_request)
                {
                    case "รอการอนุมัติ":
                        strAfterwhere = " and (approve_when is null and cancel_when is null) ";
                        break;
                    case "อนุมัติแล้ว":
                        strAfterwhere = " and approve_when is not null and cancel_when is null ";
                        break;
                    case "รายการตีกลับ":
                        strAfterwhere = " and cancel_when is not null and approve_when is null ";
                        break;
                    case "รายการทั้งหมด":
                        strAfterwhere = " ";
                        break;
                }
                strSQL = " SELECT requisition_code,requisition_date,rq.job_site_seq,request_emp_seq,rq.icm_obj_type_seq "
                        +" ,description,remark,approve_emp_seq,js.job_site_name ,ojt.icm_obj_type_name "
                        +" ,concat(coalesce(mp.prefix_name),'',coalesce(emp.first_name, ''), '  ', coalesce(emp.last_name, '')) as emp_name  "
                        +" ,concat('คุณ','',coalesce(upemp.first_name, ''), '  ', coalesce(upemp.last_name, '')) as approve_name,upemp.emp_seq as approve_emp_seq "
                        + " ,case when (approve_when is null and cancel_when is null)  then 'รอการอนุมัติ' when (approve_when is not null and cancel_when is null) then 'อนุมัติแล้ว' when (cancel_when is not null and approve_when is null) then 'รายการตีกลับ' end status_name "
                        +" FROM icm_requisition rq "
                        +" LEFT JOIN hrm_ps_employees emp on rq.request_emp_seq = emp.emp_seq "
                        +" LEFT JOIN  hrm_mp_positions p on emp.pos_seq = p.pos_seq "
                        +" LEFT JOIN  hrm_mp_positions pp on p.pos_working_upper_seq = pp.pos_seq "
                        +" LEFT JOIN hrm_ps_employees upemp on pp.pos_seq =upemp.pos_seq "
                        +" LEFT JOIN mas_name_prefixes mp on emp.name_prefix_seq = mp.name_prefix_seq "
                        +" LEFT JOIN hrm_mp_job_sites js ON emp.working_job_site_seq = js.job_site_seq "
                        +" LEFT JOIN icm_mas_object_type ojt ON rq.icm_obj_type_seq = ojt.icm_obj_type_seq "
                        +" WHERE rq.record_status<>'D' " + strAfterwhere
                        +" ORDER BY  requisition_code DESC ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_Requisition info = new M_Requisition();
                        info.requisition_code = drc[i]["requisition_code"].ToString();
                        info.requisition_date = Convert.ToDateTime(drc[i]["requisition_date"]);
                        info.job_site_seq = cn.ConvertNullInt(drc[i]["job_site_seq"]);
                        info.request_emp_seq = Convert.ToInt32(drc[i]["request_emp_seq"]);
                        info.icm_obj_type_seq = Convert.ToInt32(drc[i]["icm_obj_type_seq"]);
                        info.description = drc[i]["description"].ToString();
                        info.remark = drc[i]["remark"].ToString();
                        info.approve_emp_seq = cn.ConvertNullInt(drc[i]["approve_emp_seq"]);
                        info.job_site_name = drc[i]["job_site_name"].ToString();
                        info.employee_name = drc[i]["emp_name"].ToString();
                        info.approve_name = drc[i]["approve_name"].ToString();
                        info.icm_obj_type_name = drc[i]["icm_obj_type_name"].ToString();
                        info.status_name = drc[i]["status_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
                //return null;
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }
        public IList<M_Requisition> GetListForApproveFillByEmpSeq(Nullable<int> Approver,string StatusRequest)
        {
            string strSQL;
            string strAfterwhere = "";
            DataRowCollection drc = null;
            IList<M_Requisition> infoList = new List<M_Requisition>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);

                dbManager.AddParameters(0, "@Approver", Approver);
                dbManager.AddParameters(1, "@StatusRequest", StatusRequest);
                dbManager.AddParameters(2, "@DeleteRecord", SystemInfo._DeleteRecordStatus);

                switch (StatusRequest)
                {
                    case "รอการอนุมัติ":
                        strAfterwhere = " (approve_when is null and cancel_when is null) ";
                        break;
                    case "อนุมัติแล้ว":
                        strAfterwhere = " approve_when is not null and cancel_when is null ";
                        break;
                    case "รายการตีกลับ":
                        strAfterwhere = " cancel_when is not null and approve_when is null ";
                        break;
                    case "รายการทั้งหมด":
                        strAfterwhere = " ";
                        break;
                }
                strSQL = " SELECT requisition_code,requisition_date,rq.job_site_seq,request_emp_seq,rq.icm_obj_type_seq "
                         + " ,description,remark,approve_emp_seq,js.job_site_name ,ojt.icm_obj_type_name "
                         + " ,concat(mp.prefix_name, emp.first_name, '  ', emp.last_name) as emp_name  "
                         + " ,concat('คุณ','',coalesce(upemp.first_name, ''), '  ', coalesce(upemp.last_name, '')) as approve_name,upemp.emp_seq as approve_emp_seq "
                         + " ,case when (approve_when is null and cancel_when is null)  then 'รอการอนุมัติ' when (approve_when is not null and cancel_when is null) then 'อนุมัติแล้ว' when (cancel_when is not null and approve_when is null) then 'รายการตีกลับ' end status_name  "
                         + " FROM ICM_REQUISITION rq "
                         + " LEFT JOIN HRM_PS_EMPLOYEES emp ON rq.request_emp_seq = emp.emp_seq "
                         + " LEFT JOIN HRM_MP_POSITIONS p ON emp.pos_seq = p.pos_seq "
                         + " LEFT JOIN HRM_MP_POSITIONS pp ON p.pos_working_upper_seq = pp.pos_seq "
                         + " LEFT JOIN HRM_PS_EMPLOYEES upemp ON pp.pos_seq = upemp.pos_seq "
                         + " LEFT JOIN MAS_NAME_PREFIXES mp ON emp.name_prefix_seq = mp.name_prefix_seq "
                         + " LEFT JOIN HRM_MP_JOB_SITES js ON emp.working_job_site_seq = js.job_site_seq "
                         + " LEFT JOIN ICM_MAS_OBJECT_TYPE ojt ON rq.ICM_OBJ_TYPE_SEQ = ojt.ICM_OBJ_TYPE_SEQ "
                         + " WHERE rq.RECORD_STATUS <> @DeleteRecord"
                         + (Approver.HasValue ? " AND upemp.EMP_SEQ = @Approver" : "")
                         + " AND " + strAfterwhere
                         + " ORDER BY REQUISITION_CODE DESC ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_Requisition info = new M_Requisition();
                        info.requisition_code = drc[i]["requisition_code"].ToString();
                        info.requisition_date = Convert.ToDateTime(drc[i]["requisition_date"]);
                        info.job_site_seq = cn.ConvertNullInt(drc[i]["job_site_seq"]);
                        info.request_emp_seq = Convert.ToInt32(drc[i]["request_emp_seq"]);
                        info.icm_obj_type_seq = Convert.ToInt32(drc[i]["icm_obj_type_seq"]);
                        info.description = drc[i]["description"].ToString();
                        info.remark = drc[i]["remark"].ToString();
                        info.approve_emp_seq = Convert.ToInt32(drc[i]["approve_emp_seq"]);
                        info.job_site_name = drc[i]["job_site_name"].ToString();
                        info.employee_name = drc[i]["emp_name"].ToString();
                        info.approve_name = drc[i]["approve_name"].ToString();
                        info.icm_obj_type_name = drc[i]["icm_obj_type_name"].ToString();
                        info.status_name = drc[i]["status_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }
        public IList<M_Requisition> GetListCutstock(string status_request)
        {
            string strSQL;
            string strAfterwhere = "";
            DataRowCollection drc = null;
            IList<M_Requisition> infoList = new List<M_Requisition>();
            try
            {
                dbManager.Open();
                switch (status_request)
                {
                    case "รอการตัดเบิก":
                        strAfterwhere = " and cutstock_when is null ";
                        break;
                    case "ตัดเบิกแล้ว":
                        strAfterwhere = " and cutstock_when is not null ";
                        break;
                    case "รายการทั้งหมด":
                        strAfterwhere = " ";
                        break;
                }
                strSQL =  " SELECT requisition_code,requisition_date,rq.job_site_seq,request_emp_seq,rq.icm_obj_type_seq "
                         +" ,description,remark,approve_emp_seq,js.job_site_name ,ojt.icm_obj_type_name "
                         +" ,concat(coalesce(mp.prefix_name),'',coalesce(emp.first_name, ''), '  ', coalesce(emp.last_name, '')) as emp_name  "
                         +" ,concat('คุณ','',coalesce(upemp.first_name, ''), '  ', coalesce(upemp.last_name, '')) as approve_name,upemp.emp_seq as approve_emp_seq "
                         + " ,case when (cutstock_when is null)  then 'รอการตัดเบิก' when (cutstock_when is not null) then 'ตัดเบิกแล้ว'  end status_name   "
                         + " ,concat('คุณ','',coalesce(empcut.first_name, ''), '  ', coalesce(empcut.last_name, '')) as cutstock_name,movement_code "
                         +" FROM icm_requisition rq "
                         +" LEFT JOIN hrm_ps_employees emp on rq.request_emp_seq = emp.emp_seq "
                         +" LEFT JOIN  hrm_mp_positions p on emp.pos_seq = p.pos_seq "
                         +" LEFT JOIN  hrm_mp_positions pp on p.pos_working_upper_seq = pp.pos_seq "
                         +" LEFT JOIN hrm_ps_employees upemp on pp.pos_seq =upemp.pos_seq "
                         +" LEFT JOIN mas_name_prefixes mp on emp.name_prefix_seq = mp.name_prefix_seq "
                         +" LEFT JOIN hrm_mp_job_sites js ON emp.working_job_site_seq = js.job_site_seq "
                         +" LEFT JOIN icm_mas_object_type ojt ON rq.icm_obj_type_seq = ojt.icm_obj_type_seq "
                         +" LEFT JOIN hrm_ps_employees empcut ON rq.cutstock_by = empcut.emp_seq "
                         +" WHERE rq.record_status<>'D' and approve_when is not null "+strAfterwhere
                         + " ORDER BY  requisition_date,requisition_code DESC ";

                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_Requisition info = new M_Requisition();
                        info.requisition_code = drc[i]["requisition_code"].ToString();
                        info.requisition_date = Convert.ToDateTime(drc[i]["requisition_date"]);
                        info.job_site_seq = cn.ConvertNullInt(drc[i]["job_site_seq"]);
                        info.job_site_name = drc[i]["job_site_name"].ToString();
                        info.request_emp_seq = Convert.ToInt32(drc[i]["request_emp_seq"]);
                        info.icm_obj_type_seq = Convert.ToInt32(drc[i]["icm_obj_type_seq"]);
                        info.description = drc[i]["description"].ToString();
                        info.remark = drc[i]["remark"].ToString();
                        info.approve_emp_seq = Convert.ToInt32(drc[i]["approve_emp_seq"]);
                        info.job_site_name = drc[i]["job_site_name"].ToString();
                        info.employee_name = drc[i]["emp_name"].ToString();
                        info.approve_name = drc[i]["approve_name"].ToString();
                        info.icm_obj_type_name = drc[i]["icm_obj_type_name"].ToString();
                        info.status_name = drc[i]["status_name"].ToString();
                        info.movement_code = drc[i]["movement_code"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public M_Requisition GetListFillBySeq(string requisition_code)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_Requisition info = new M_Requisition();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@requisition_code", requisition_code);

                //strSQL = " SELECT requisition_code,requisition_date,rq.job_site_seq,request_emp_seq,rq.icm_obj_type_seq "
                //         + " ,description,remark,approve_emp_seq,js.job_site_name "
                //         + " ,concat('คุณ' +' '+ coalesce(emp.first_name, ''), '  ', coalesce(emp.last_name, ''))   as emp_name,ojt.icm_obj_type_name "
                //         + " ,concat('คุณ' +' ' + coalesce(emp1.first_name, ''), '  ', coalesce(emp1.last_name, ''))   as approve_name "
                //         + " FROM icm_requisition rq "
                //         + " LEFT JOIN hrm_mp_job_sites  js ON rq.job_site_seq = js.job_site_seq "
                //         + " LEFT JOIN hrm_ps_employees emp ON rq.request_emp_seq= emp.emp_seq "
                //         + " LEFT JOIN icm_mas_object_type ojt ON rq.icm_obj_type_seq = ojt.icm_obj_type_seq "
                //         + " LEFT JOIN hrm_ps_employees emp1 ON rq.request_emp_seq= emp1.emp_seq "
                //         + " WHERE rq.record_status<>'D'  and requisition_code LIKE '%' '" + @requisition_code + "'  '%' ";
                strSQL = " SELECT requisition_code,requisition_date,rq.job_site_seq,request_emp_seq,rq.icm_obj_type_seq "
                        + " ,description,remark,approve_emp_seq,js.job_site_name ,ojt.icm_obj_type_name "
                        + " ,concat(coalesce(mp.prefix_name),'',coalesce(emp.first_name, ''), '  ', coalesce(emp.last_name, '')) as emp_name  "
                        + " ,concat('คุณ','',coalesce(upemp.first_name, ''), '  ', coalesce(upemp.last_name, '')) as approve_name,upemp.emp_seq as approve_emp_seq "
                        + " ,case when (approve_when is null and cancel_when is null)  then 'รอการอนุมัติ' when approve_when is not null then 'อนุมัติแล้ว' when cancel_when is not null then 'รายการตีกลับ' end status_name "
                        + " FROM icm_requisition rq "
                        + " LEFT JOIN hrm_ps_employees emp on rq.request_emp_seq = emp.emp_seq "
                        + " LEFT JOIN  hrm_mp_positions p on emp.pos_seq = p.pos_seq "
                        + " LEFT JOIN  hrm_mp_positions pp on p.pos_working_upper_seq = pp.pos_seq "
                        + " LEFT JOIN hrm_ps_employees upemp on pp.pos_seq =upemp.pos_seq "
                        + " LEFT JOIN mas_name_prefixes mp on emp.name_prefix_seq = mp.name_prefix_seq "
                        + " LEFT JOIN hrm_mp_job_sites js ON emp.working_job_site_seq = js.job_site_seq "
                        + " LEFT JOIN icm_mas_object_type ojt ON rq.icm_obj_type_seq = ojt.icm_obj_type_seq "
                        + " WHERE rq.record_status<>'D' and requisition_code LIKE '%' '" + @requisition_code + "'  '%' ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.requisition_code = drc[0]["requisition_code"].ToString();
                    info.requisition_date = Convert.ToDateTime(drc[0]["requisition_date"]);
                    info.job_site_seq = cn.ConvertNullInt(drc[0]["job_site_seq"]);
                    info.request_emp_seq = Convert.ToInt32(drc[0]["request_emp_seq"]);
                    info.icm_obj_type_seq = Convert.ToInt32(drc[0]["icm_obj_type_seq"]);
                    info.description = drc[0]["description"].ToString();
                    info.remark = drc[0]["remark"].ToString();
                    info.approve_emp_seq = Convert.ToInt32(drc[0]["approve_emp_seq"]);
                    info.job_site_name = drc[0]["job_site_name"].ToString();
                    info.employee_name = drc[0]["emp_name"].ToString();
                    info.approve_name = drc[0]["approve_name"].ToString();
                    info.icm_obj_type_name = drc[0]["icm_obj_type_name"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }
        public M_Requisition GetListTransferFillBySeq(string requisition_code)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_Requisition info = new M_Requisition();
            try
            {
                dbManager.Open();

                strSQL =  " SELECT requisition_code,requisition_date,job_site_seq,request_emp_seq "
                         +" ,rq.icm_obj_type_seq,description,remark,approve_emp_seq,icm_obj_type_name "
                         +" FROM icm_requisition rq "
                         +" LEFT JOIN icm_mas_object_type obj ON rq.icm_obj_type_seq = obj.icm_obj_type_seq "
                         +" WHERE rq.record_status<>'D' "
                         +" and requisition_code LIKE '%' '" + requisition_code + "'  '%' ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.requisition_code = drc[0]["requisition_code"].ToString();
                    info.requisition_date = Convert.ToDateTime(drc[0]["requisition_date"]);
                    info.job_site_seq = cn.ConvertNullInt(drc[0]["job_site_seq"]);
                    info.request_emp_seq = Convert.ToInt32(drc[0]["request_emp_seq"]);
                    info.icm_obj_type_seq = Convert.ToInt32(drc[0]["icm_obj_type_seq"]);
                    info.description = drc[0]["description"].ToString();
                    info.remark = drc[0]["remark"].ToString();
                    info.approve_emp_seq = cn.ConvertNullInt(drc[0]["approve_emp_seq"]);
                    info.icm_obj_type_name = drc[0]["icm_obj_type_name"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }
        public M_Requisition GenerateRequisitionCode()
        {
            string strSQL;
            DataRowCollection drc = null;
            M_Requisition info = new M_Requisition();
            try
            {
                dbManager.Open();
               // dbManager.CreateParameters(0);
               // dbManager.AddParameters(0, "@requisition_code", requisition_code);

                strSQL =  " SELECT case when  (Year(Now()) <2500) then Year(Now())+543 else Year(Now()) end YearValue , Month(Now()) as MonthValue " 
                         +" ,COUNT(requisition_code)+1 as running  "
                         +" FROM icm_receive "
                         +" WHERE YEAR(created_when) = YEAR(Now()) and  Month(created_when) = Month(Now())  -- and (right(left(requisition_code,19),12) = @requisition_code) ";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.str_year = drc[0]["YearValue"].ToString();
                    info.str_month = drc[0]["MonthValue"].ToString();
                    info.requisition_running = drc[0]["running"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        public void Insert_Requisition(M_Requisition info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(11);
                dbManager.AddParameters(0, "@requisition_code", info.requisition_code);
                dbManager.AddParameters(1, "@requisition_date", info.requisition_date);
                dbManager.AddParameters(2, "@request_emp_seq", info.request_emp_seq);
                dbManager.AddParameters(3, "@description", info.description);
                dbManager.AddParameters(4, "@remark", info.remark);
                dbManager.AddParameters(5, "@record_status", info.record_status);
                dbManager.AddParameters(6, "@approve_emp_seq", info.approve_emp_seq);
                dbManager.AddParameters(7, "@created_by", info.created_by);
                dbManager.AddParameters(8, "@created_when", info.created_when);
                dbManager.AddParameters(9, "@icm_obj_type_seq", info.icm_obj_type_seq);
                dbManager.AddParameters(10, "@job_site_seq", info.job_site_seq);

                strSQL = " INSERT INTO icm_requisition "
                        + " (requisition_code,requisition_date,request_emp_seq "
                        + " ,description,remark,record_status,approve_emp_seq,job_site_seq "
                        + " ,created_by,created_when,icm_obj_type_seq) "
                        + " VALUES "
                        + " (@requisition_code,@requisition_date,@request_emp_seq "
                        + " ,@description,@remark,@record_status,@approve_emp_seq,@job_site_seq "
                        + " ,@created_by,@created_when,@icm_obj_type_seq) ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public void Update_Requisition(M_Requisition info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);
                dbManager.AddParameters(0, "@requisition_code", info.requisition_code);
                dbManager.AddParameters(1, "@record_status", info.record_status);
                dbManager.AddParameters(2, "@updated_by", info.updated_by);
                dbManager.AddParameters(3, "@updated_when", info.updated_when);
                dbManager.AddParameters(4, "@cancel_when", info.cancel_when);

                strSQL = " UPDATE icm_requisition "
                        + " SET record_status = @record_status "
                        + " ,updated_by =@updated_by "
                        + " ,updated_when = @updated_when "
                        + " ,cancel_when = @cancel_when "
                        + " WHERE requisition_code = @requisition_code ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void Approve_Requisition(M_Requisition info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@requisition_code", info.requisition_code);
                dbManager.AddParameters(1, "@approve_flag", info.approve_flag);
                dbManager.AddParameters(2, "@approve_emp_seq", info.approve_emp_seq);
                dbManager.AddParameters(3, "@approve_when", info.approve_when);

                strSQL = " UPDATE icm_requisition "
                        + " SET approve_flag = @approve_flag "
                        + " ,approve_emp_seq =@approve_emp_seq "
                        + " ,approve_when = @approve_when "
                        + " WHERE requisition_code = @requisition_code ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void Cancel_Requisition(M_Requisition info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(5);
                dbManager.AddParameters(0, "@requisition_code", info.requisition_code);
                dbManager.AddParameters(1, "@cancel_flag", info.cancel_flag);
                dbManager.AddParameters(2, "@cancel_remark", info.cancel_remark);
                dbManager.AddParameters(3, "@cancel_by", info.cancel_by);
                dbManager.AddParameters(4, "@cancel_when", info.cancel_when);

                strSQL = " UPDATE icm_requisition "
                        + " SET cancel_flag = @cancel_flag "
                        + " ,cancel_remark =@cancel_remark "
                        + " ,cancel_by = @cancel_by "
                        + " ,cancel_when = @cancel_when "
                        + " WHERE requisition_code = @requisition_code ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }
        public void CutStock_Requisition(M_Requisition info)
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@requisition_code", info.requisition_code);
                dbManager.AddParameters(1, "@cutstock_by", info.cutstock_by);
                dbManager.AddParameters(2, "@cutstock_when", info.cutstock_when);
                dbManager.AddParameters(3, "@movement_code", info.movement_code);

                strSQL = " UPDATE icm_requisition "
                        + " SET cutstock_by = @cutstock_by "
                        + " ,cutstock_when =@cutstock_when "
                        + " ,movement_code =@movement_code "
                        + " WHERE requisition_code = @requisition_code ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }


    }
}
